<template>
  <div class="infinite-container">
    <div class="bgwhite">
      <mu-list>
        <mu-list-item title="更改手机号" @click="go('/setting/update-mobile')">
          <i class="iconfont icon-small-arrow-right t3" slot="right"></i>
        </mu-list-item>
        <mu-divider/>
        <mu-list-item title="账号解除绑定" @click="openConfirmDialog()">
          <i class="iconfont icon-small-arrow-right t3" slot="right"></i>
        </mu-list-item>
         <mu-list-item title="意见反馈" @click="go('/setting/feedback')">
          <i class="iconfont icon-small-arrow-right t3" slot="right"></i>
        </mu-list-item>
        <mu-divider/>
      </mu-list>
    </div>
    <!-- confirm dialog -->
    <mu-dialog :open="confirmDialog"  @close="close">
      <div class="center">解绑后无法操作预约挂号等功能，是否继续？</div>
      <mu-flat-button slot="actions" @click="close" default label="取消" fullWidth/>
      <mu-flat-button slot="actions" primary @click="unBind" label="继续"/>
    </mu-dialog>
  </div>
</template>

<script>
  import {commonAjax} from '@/api/api'
  export default {
    name: 'message',
    data () {
      return {
        confirmDialog: false,
        person: JSON.parse(sessionStorage.getItem('person'))
      }
    },
    mounted () {

    },
    methods: {
      go (url) {
        this.$router.push(url)
      },
      openConfirmDialog () {
        this.confirmDialog = true
      },
      close () {
        this.confirmDialog = false
      },
      unBind () {
        let params = {
          mobile: this.person.mobile,
          [this.$APP_PLATFORM_NAME]: sessionStorage[this.$APP_PLATFORM_NAME]
        }
        commonAjax('user/unbind', params).then(res => {
          if (res.data.code == 200) {
            sessionStorage.removeItem('familyPerson')
            sessionStorage.removeItem('person')
            sessionStorage.removeItem('dept')
            sessionStorage.removeItem('doctor')
            sessionStorage.removeItem('currentOrder')
            sessionStorage.removeItem('appointTime')
            sessionStorage.removeItem('accessToken')
            sessionStorage.removeItem('order')
            sessionStorage.removeItem('selectedSchedule')
            this.$store.commit('UPDATE_TOAST', {
              message: res.data.msg,
              fn: () => this.$router.replace('/login')
            })
          }
        })
      }
    }
  }
</script>
<style lang="less" scoped>
  @import '../../common/css/vars.less';
  @import '../../common/css/flex.css';
</style>
